<?php
function query_to_hash($query)
{
	$result = mysql_query($query);
	$row = false;
	if (mysql_num_rows($result) > 0)
		$row = mysql_fetch_array($result);
	return $row;
}

function generate_menu_recursive($parent)
{
	global $pageurl;
	
	$sql = "SELECT id,author,title,urltitle,content,type,security_level,security_group FROM `dcms_pages` WHERE visible = 'T' AND parent=$parent order by `order`";
	$result = mysql_query($sql);
	if (mysql_num_rows($result) == 0)
		return "";
		
	$menu = "<ul>";
	while ($row = mysql_fetch_array($result))
	{
		if (check_permission($row['security_level'], $row['security_group']))
		{
			$ornament = (isset($pageurl) && $row['urltitle'] == $pageurl) ? "&raquo; " : "";
			$link = ($row['type'] == 'page') ? "page.php?p=$row[urltitle]" : $row['urltitle'];
			$menu .= "<li>$ornament<a href=\"$link\">$row[title]</a>";
			$menu .= generate_menu_recursive($row['id']);
			$menu .= "</li>";
		}
	}
	$menu .= "</ul>";
	return $menu;
}

function generate_menu()
{
	return generate_menu_recursive(0);
}

function sp_delete_id($table, $id)
{
	return mysql_query("DELETE FROM " . addslashes($table) . " WHERE id=" . addslashes($id));
}
?>
